<!--
Copyright (C) 2011 Apple Computer, Inc.  All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../resources/js-test-pre.js"></script>
<script src="../resources/webgl-test.js"></script>
<script src="../resources/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>

<script>
var wtu = WebGLTestUtils;
description("Tests calling WebGL APIs with various types");

var context = wtu.create3DContext();
var program = wtu.loadStandardProgram(context);
var shader = wtu.loadStandardVertexShader(context);
var shouldGenerateGLError = wtu.shouldGenerateGLError;

assertMsg(program != null, "Program Compiled");
assertMsg(shader != null, "Shader Compiled");

var loc = context.getUniformLocation(program, "u_modelViewProjMatrix");
assertMsg(loc != null, "getUniformLocation succeeded");

var buffer = context.createBuffer();
context.bindBuffer(context.ARRAY_BUFFER, buffer);
var texture = context.createTexture();
context.bindTexture(context.TEXTURE_2D, texture);
context.useProgram(program);

var args = [
  { type: "number", value: 0 },
  { type: "number", value: 2 },
  { type: "string that is NaN", value: "foo", },
  { type: "string that is number", value: "2", },
  { type: "null", value: null },
  { type: "Empty Array", value: [] },
  { type: "Object", value: {} },
  { type: "Array of Number", value: [2] },
  { type: "Array of String", value: ["foo"] },
  { type: "Array of String that is number", value: ["0"] },
  { type: "Array of String that is number", value: ["2"] },
  { type: "TypedArray", value: new Float32Array(1) }
];

var argument;

for (var i = 0; i < args.length; ++i) {
  argument = args[i].value;
  var func1 = shouldBeUndefined;
  var func2 = shouldBeNonNull;
  if (argument == 2) {
    func2 = shouldBeNull;
  }
  func3 = shouldBeNull;
  debug("");
  debug("testing type of " + args[i].type + " : value = " + argument);
  func1("context.bindAttribLocation(program, argument, 'foo')");
  func1("context.blendColor(argument, argument, argument, argument)");
  func1("context.bufferData(context.ARRAY_BUFFER, argument, context.STATIC_DRAW)");
  func1("context.bufferData(context.ARRAY_BUFFER, new Float32Array(10), context.STATIC_DRAW)");
  func1("context.bufferSubData(context.ARRAY_BUFFER, argument, new Float32Array(2))");
  func1("context.clear(argument)")
  func1("context.clearColor(argument, 0, 0, 0)");
  func1("context.clearColor(0, argument, 0, 0)");
  func1("context.clearColor(0, 0, argument, 0)");
  func1("context.clearColor(0, 0, 0, argument)");
  func1("context.clearDepth(argument)");
  func1("context.clearStencil(argument)");
  func1("context.copyTexImage2D(context.TEXTURE_2D, argument, context.RGBA, 0, 0, 1, 1, 0)");
  func1("context.copyTexImage2D(context.TEXTURE_2D, 0, context.RGBA, argument, 0, 1, 1, 0)");
  func1("context.copyTexImage2D(context.TEXTURE_2D, 0, context.RGBA, 0, argument, 1, 1, 0)");
  func1("context.copyTexImage2D(context.TEXTURE_2D, 0, context.RGBA, 0, 0, argument, 1, 0)");
  func1("context.copyTexImage2D(context.TEXTURE_2D, 0, context.RGBA, 0, 0, 0, argument, 0)");
  func1("context.copyTexSubImage2D(context.TEXTURE_2D, argument, 0, 0, 0, 0, 0, 0)");
  func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, argument, 0, 0, 0, 0, 0)");
  func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, argument, 0, 0, 0, 0)");
  func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, 0, argument, 0, 0, 0)");
  func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, 0, 0, argument, 0, 0)");
  func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, 0, 0, 0, argument, 0)");
  func1("context.copyTexSubImage2D(context.TEXTURE_2D, 0, 0, 0, 0, 0, 0, argument)");
  func1("context.depthMask(argument)");
  func1("context.depthRange(argument, 1)");
  func1("context.depthRange(0, argument)");
  func1("context.drawArrays(context.POINTS, argument, 1)");
  func1("context.drawArrays(context.POINTS, 0, argument)");
  //func1("context.drawElements(...)");
  func1("context.enableVertexAttribArray(argument)");
  func1("context.disableVertexAttribArray(argument)");
  func2("context.getActiveAttrib(program, argument)");
  func2("context.getActiveUniform(program, argument)");
  func3("context.getParameter(argument)");
  func1("context.lineWidth(argument)");
  func1("context.polygonOffset(argument, 0)");
  func1("context.polygonOffset(0, argument)");
  //func1("context.readPixels(...)");
  //func1("context.renderbufferStorage(...)");
  func1("context.sampleCoverage(argument, 0)");
  func1("context.sampleCoverage(0, argument)");
  func1("context.scissor(argument, 0, 10, 10)");
  func1("context.scissor(0, argument, 10, 10)");
  func1("context.scissor(0, 0, argument, 10)");
  func1("context.scissor(0, 0, 10, argument)");
  func1("context.shaderSource(shader, argument)");
  func1("context.stencilFunc(context.NEVER, argument, 255)");
  func1("context.stencilFunc(context.NEVER, 0, argument)");
  //func1("context.stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)");
  func1("context.stencilMask(argument)");
  //func1("context.stencilMaskSeparate(context.FRONT, argument);
  //func1("context.texImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, ArrayBufferView pixels)");
  //func1("context.texParameterf(GLenum target, GLenum pname, GLfloat param)");
  //func1("context.texParameteri(GLenum target, GLenum pname, GLint param)");
  //func1("context.texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,GLsizei width, GLsizei height,GLenum format, GLenum type, ArrayBufferView pixels)");
  func1("context.uniform1i(loc, argument)");
  func1("context.uniform2i(loc, argument, 0)");
  func1("context.uniform2i(loc, 0, argument)");
  func1("context.uniform3i(loc, argument, 0, 0)");
  func1("context.uniform3i(loc, 0, argument, 0)");
  func1("context.uniform3i(loc, 0, 0, argument)");
  func1("context.uniform4i(loc, argument, 0, 0, 0)");
  func1("context.uniform4i(loc, 0, argument, 0, 0)");
  func1("context.uniform4i(loc, 0, 0, argument, 0)");
  func1("context.uniform4i(loc, 0, 0, 0, argument)");
  func1("context.uniform1f(loc, argument)");
  func1("context.uniform2f(loc, argument, 0)");
  func1("context.uniform2f(loc, 0, argument)");
  func1("context.uniform3f(loc, argument, 0, 0)");
  func1("context.uniform3f(loc, 0, argument, 0)");
  func1("context.uniform3f(loc, 0, 0, argument)");
  func1("context.uniform4f(loc, argument, 0, 0, 0)");
  func1("context.uniform4f(loc, 0, argument, 0, 0)");
  func1("context.uniform4f(loc, 0, 0, argument, 0)");
  func1("context.uniform4f(loc, 0, 0, 0, argument)");
}

successfullyParsed = true;
</script>

<script src="../../resources/js-test-post.js"></script>
</body>
</html>

